$('.del').click(function() {
	$(this).parent().css('display', 'none')
	$('form').css('margin-top', '5vh')
})

$('.submit').click(function() {
	get_login();
})
//回车键触发
$(document).keydown(function(event) {
	if(event.keyCode == 13) {
		$(".submit").click();
	}
});

function get_login() {
	var user_name = $('#user_name').val();
	var psd = $('#password').val();
	var regName = /^[ \u4e00-\u9fa5A-Za-z]+$/;
	var isAutoLoginId = $('#isAutoLoginId').checked;
	var storage = window.localStorage;

	if(user_name == "") {
		layer.msg('用户名不能为空', {
			icon: 2,
			time: 1500,
		});
		return false;
	}
	if(psd == "") {
		layer.msg('密码不能为空', {
			icon: 2,
			time: 1500
		});
		return false;
	}

	$.ajax({
		type: "post",
		url: "http://"+com_url+"//admin/login",
		data: {
			user_name: user_name,
			passwords: psd
		},
		success: function(res) {
			var Ress = JSON.parse(res);
			var msg = Ress.msg;
			var access_id = Ress.data.access;
			var falg;
			if(access_id==""){
				falg=false;
				layer.msg("没有权限登录", {
					icon: 0,
					time: 1500
				});
				return false;
			}else{
					falg=true;
				}
			localStorage.setItem("falg", falg);//放入session
			if(Ress.code == '200'&&access_id) {
				localStorage.setItem("picTabNum", '0');
				layer.msg(msg, {
					icon: 1,
					time: 2000
				});
				var ApiAuth = Ress.data.apiAuth;
				document.cookie = "ApiAuth=" + escape(ApiAuth);
				var user_name = Ress.data.user_name;
				document.cookie = "user_name=" + escape(user_name);
				var role_id = Ress.data.role_id;
				document.cookie = "role_id=" + escape(role_id);
				
				if(access_id==""){
					layer.msg("没有权限",'{icon:0}')
				}
				var Herf_id = Ress.data.access[0].title;
//				document.cookie = "Herf_id=" + escape(Herf_id);
				localStorage.setItem("Herf_id", Herf_id);//放入session
				setTimeout(function() {
					window.location.href = "index.html";
				}, 400);
				var floor = Ress.data.floor;
				document.cookie = "floor=" + escape(floor);
				var zxh = Ress.data.zxh;
				document.cookie = "zxh=" + escape(zxh);
				var zxhdq = Ress.data.zxhdq;
				document.cookie = "zxhdq=" + escape(zxhdq);
				$.each(access_id, function(index, curr) {
					if(access_id[index].menu_id == "1000") { //资源线索
						var index_id = access_id[index].menu_id;
						document.cookie = "index_id=" + escape(index_id);
					}
					if(access_id[index].menu_id == "1001") { //我的客户
						var MyUser_id = access_id[index].menu_id;
						document.cookie = "MyUser_id=" + escape(MyUser_id);
					}
					if(access_id[index].menu_id == "1003") {
						var Business_id = access_id[index].menu_id;
						document.cookie = "Business_id=" + escape(Business_id);
					}
					if(access_id[index].menu_id == "1004") { //数据中心
						var service_id = access_id[index].menu_id;
						document.cookie = "service_id=" + escape(service_id);
					}
					if(access_id[index].menu_id == "1005") {
						var statis_id = access_id[index].menu_id;
						document.cookie = "statis_id=" + escape(statis_id);
					}
					if(access_id[index].menu_id == "1010") { //组织架构
						var oganization_id = access_id[index].menu_id;
						document.cookie = "oganization_id=" + escape(oganization_id);
					}
					if(access_id[index].menu_id == "1007") {
						var Account_id = access_id[index].menu_id;
						document.cookie = "Account_id=" + escape(Account_id);
					}
					if(access_id[index].menu_id == "1016") {
						var Resour_id = access_id[index].menu_id;
						document.cookie = "Resour_id=" + escape(Resour_id);
					}
					if(access_id[index].menu_id == "1030") {
						var Stati_id = access_id[index].menu_id;
						document.cookie = "Stati_id=" + escape(Stati_id);
					}
				})
			} else{
				layer.msg(msg, {
					icon: 2,
					time: 2000
				});
			}

			//			var d = new Date();
			//			d.setHours(d.getHours() + (24 * 3)); //保存时间
			//			document.cookie = "ApiAuth="+ApiAuth+"; expires=" + d.toGMTString();
			//token
			//用户名
			document.cookie = "user_name=" + escape(user_name);
		},
		error: function(res) {
			layer.msg('数据库异常')
		}
	});
}